var facebooktab = {    
    lightboxPaddingTop: 180,
    lightboxAutoAdjust: false,
    likelightbox: null,  
    likeboxNextID: 0,
    likeboxPreID: 0,
    likecloser: function(e) {
      if(facebooktab.likelightbox == null) {
          return void(0);
      }
      var parent = document.id(facebooktab.likelightbox).getParent('.lightface');
      if(e.target != parent && !parent.contains(e.target)) {
          if(facebooktab.likelightbox != null) {
              facebooktab.likelightbox.close();
          }
        
      }
      return void(0);
    },
    resizeLightbox: function(){
        jQuery(".lightface").css("top", facebooktab.lightboxPaddingTop);
    },
    
    showLikeLightbox: function(objectID) {        
        if(objectID == 0){
            return void(0);
        }        
        var randString = Math.random();
        var objectURL = '?action=fblikebox&rnd=' + randString + "&data_id=" + objectID;
        if(facebooktab.likelightbox == null) {
            facebooktab.likelightbox = new LightFace.Request({
                url: objectURL,
                width: 420, 
                draggable: false,
                resetOnScroll: facebooktab.lightboxAutoAdjust,
                zIndex: 999,
                onOpen:function(){
                    if(!facebooktab.lightboxAutoAdjust){
                        facebooktab.resizeLightbox();
                    }                  
                },
                onComplete:function(){
                    if(!facebooktab.lightboxAutoAdjust){
                        facebooktab.resizeLightbox();
                    } else {
//                        window.setTimeout("facebooktab.likelightbox._position()", 1000);
                        
                    }   
                },
                buttons: [
                    {
                        title: 'Đóng', 
                        event: function() {
                            this.close();
                        }, 
                        color: 'blue'
                    }
                ],
                request:{
                    evalScripts: true
                },
                title: 'Thỏa thuận',
                keys: {
                    left: function() { 
                        facebooktab.showLikeLightbox(facebooktab.likeboxPreID);
                    },
                    right: function() { 
                        facebooktab.showLikeLightbox(facebooktab.likeboxNextID);
                    },
                    esc: function() {
                      this.close();
                    }
                  }
            }).open();
        } else {
            facebooktab.likelightbox.open();            
            facebooktab.likelightbox.load(objectURL);
        }
        return void(0);
    },
    
    shareData: {},
    
    setFacebookShareData: function(shareData)
    {
        facebooktab.shareData = shareData;
    },
    
    share: function(){
        var shareData = facebooktab.shareData;
        FB.ui(
                {
                    method: 'feed',
                    picture: shareData.picture,
                    name: shareData.name,
                    caption: shareData.caption,
                    link:shareData.url,
                    action_links: [
                        {text: shareData.actionText, href: shareData.url}
                    ]
                },
                function(response) {
                    if (response && response.post_id) {
                    } else {
                    }
                }
            );
    }
};

